using System.Data;
using System.Data.SqlClient;
using Provausio.Common.Data;
using Provausio.Common.Objects;

namespace TrainingManagement.api.Models.Data.CRUD.Department
{
    public class DepartmentUpdateDataSource : NonQuerySource<BusinessObjects.Department>
    {
        public override bool Execute(BusinessObjects.Department request)
        {
            const string updateDepartment = "dbo.training_api_DepartmentUpdate";
            var parameters = new SqlParameter[2];
            parameters[0] = new SqlParameter("@Title", SqlDbType.NVarChar){Value = request.Title};
            parameters[1] = new SqlParameter("@DepartmentID", SqlDbType.Int){Value = request.DepartmentId};

            return SqlHelper.ExecuteNonQuery(
                ConnectionStrings.TrainingDb,
                CommandType.StoredProcedure,
                updateDepartment,
                parameters) != 0;
        }
    }
}